const Comment = require("../schema/comment");

// 查找评论
const findComment = (id) => {
    return Comment.findById(id);
};
// 新增评论
const addComment = (comment) => {
    return Comment.create(comment);
};

// 删除评论
const deleteComment = (id) => {
    return Comment.findByIdAndDelete(id);
};

// 博客的评论列表
const listComment = (blogId, size, page) => {
    return Comment.find({
        blog: blogId,
    })
        .populate("author")
        .select("-blog")
        .limit(size)
        .skip((page - 1) * size);
};

module.exports = {
    findComment,
    addComment,
    deleteComment,
    listComment,
};
